﻿#include "countdowntime.h"

CountDownTime::CountDownTime(QWidget *parent, Qt::WindowFlags f) :
    QLabel(parent)
{
    QLabel::setStyleSheet("QLabel{background-color:transparent;font-size: 20px; color : red;}");
    QLabel::setAlignment(Qt::AlignCenter);
    OneSecound = new QTimer(this);
    connect(this->OneSecound, SIGNAL(timeout()), this, SLOT(TimeOut()));
}
void CountDownTime::CountDownStart()
{
    OneSecound->start(1000);
}
void CountDownTime::CountDownStop()
{
    counttime = inittime;
    QLabel::setNum(counttime);
    OneSecound->stop();
}
void CountDownTime::mysetText(const QString &str)
{
    inittime = str.toInt();
    counttime = inittime;
    QLabel::setNum(inittime);
}

void CountDownTime::TimeOut()
{
    if(!text().isEmpty())
    {
        counttime--;
        if(counttime == 0)
        {
            emit CoundDownTimeisOver();
            CountDownStop();
        }
        QLabel::setNum(counttime);
    }
}
